﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TimViec.NguoiDung
{
    public partial class XemHoSo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["hoso"] != null)
                {
                    var hosoId = Convert.ToInt32(Request.QueryString["hoso"]);
                    LoadData(hosoId);
                }
                else
                {
                    Response.Redirect("/");
                }
            }
        }

        private void LoadData(int hosoId)
        {
            var user = BLL.NguoiDung.HoSo.LoadUserByHoSoId(hosoId);
            if(user!=null)
            {
                lbUserName.Text = user.UserName;
                lbGioiTinh.Text = user.Sex == true ? "Name" : "Nữ";
                lbNgaySinh.Text = user.Birth.ToString("dd/MM/yyyy");
                lbQuocTich.Text = user.tbl_DM_Tinh.tbl_DM_QuocGia.Ten;
                lbTTHN.Text = user.RelationShip;

                lbDiaChi.Text = user.DiaChi;
                lbEmail.Text="<a class='link' href='mailto:"+user.Email+"'>" + " " + user.Email + " " + "</a>";
                avatar.ImageUrl = user.UrlAvatar;
            }

            var hoso = BLL.NguoiDung.HoSo.LoadHoSo(hosoId);
            if(hoso!=null)
            {
                lbTieuDe.Text = hoso.TieuDe;
                lbTimeUpdate.Text = hoso.LastUpdate.ToString("dd/MM/yyyy");

                lbSoNamLamViec.Text = BLL.NguoiDung.HoSo.CountTotalExp(hosoId).ToString();
            }

            

            rptHocVan.DataSource = BLL.NguoiDung.HoSo.LoadHocVanForView(hosoId);
            rptHocVan.DataBind();

            rptNgoaiNgu.DataSource = BLL.NguoiDung.HoSo.LoadNgoaiNguForView(hosoId);
            rptNgoaiNgu.DataBind();

            rptKiNang.DataSource = BLL.NguoiDung.HoSo.LoadKiNangForView(hosoId);
            rptKiNang.DataBind();

            var muctieu = BLL.NguoiDung.HoSo.LoadMucTieu(hosoId);
            if(muctieu!=null)
            {
                lbViTriMongMuon.Text = muctieu.ViTriMongMuon;
                lbMucLuongGanNhat.Text = muctieu.MucLuongGanNhat.ToString();
                lbMucLuongMMTu.Text = muctieu.MucLuongMongMuonTu.ToString();
                lbMucLuongMMDen.Text = muctieu.MucLuongMongMuonTuDen.ToString();

                lbCapBac.Text = muctieu.tbl_DM_CapBacCV.Mota;


                lbLoaiCV.Text = findLoaiCV(muctieu.LoaiCongViecId.Value);

                var par = muctieu.MoiLamUaThich.Split(';');


                var str = "";
                foreach (var s in par)
                {
                    if (s != "")
                        str = BLL.Admin.TinhHelper.Get_TinhId(Int32.Parse(s)).Ten + " ; ";
                }

                lbNoiLam.Text = str;

                lbMucTieu.Text = muctieu.MucTieu;
            }
        }

        private string findLoaiCV(int id)
        {
            switch (id)
            {
                case    0:
                    return "Toàn thời gian cố định(full-time)";
                case 1:
                    return "Toàn thời gian tạm thời";
                case 2:
                    return "Bán thời gian(part-time)";
                case 3:
                    return "Bán thời gian tạm thời";
                case 4:
                    return "Thực tập(INTERSHIP)";
                case 5:
                    return "Khác";
                default:
                    return "";
            }
        }
    }
}